/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("daojiaoGD",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using ATkg.BizAppProject.DomainModels;
using ATkg.BizAppProject.IServices;
using DGZImp.Core.EFDbContext;
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json.Linq;
using static ATkg.BizAppProject.Services.daojiaoGDService;

namespace ATkg.BizAppProject.Controllers
{
    public partial class daojiaoGDController
    {
        private readonly IdaojiaoGDService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        private readonly Imaterial_plan_xieRepository _repository;//访问数据库
        public ISqlSugarClient Db = AutofacContainerModule.GetService<ServiceDbContext>()?.SqlSugarClient;


        [ActivatorUtilitiesConstructor]
        public daojiaoGDController(
            IdaojiaoGDService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }


        [HttpGet("shebeitaizhang")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> shebeitaizhang()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var r = await Service.get_info_from_bfmes();
            //var r = 0;

            //var r = 0;
            return JsonNormal(r);
        }


        [HttpGet("search_order")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> search_order()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var r = await Service.get_order_from_bfmes();
            //var r = 0;

            //var r = 0;
            return JsonNormal(r);
        }

        //[HttpGet("insert_db_gz")]
        //[AllowAnonymous]
        ////[HttpBody]
        //public async Task<JsonResult> insert_db_gz()
        ////public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        //{
        //    Console.WriteLine("get方法调用");
        //    var r = await Service.insert_db_lot();
        //    //var r = 0;

        //    //var r = 0;
        //    return JsonNormal(r);
        //}
        [HttpPost("shebei_db")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> shebei_db()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var rows = await Service.get_devices_db();
            //var r = 0;

            //var r = 0;
            return JsonNormal(rows);
        }

        [HttpGet("shebei_db_taizhang")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> shebei_db_taizhang()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var rows = await Service.get_devices_db_taizhang();
            //var r = 0;

            //var r = 0;
            return JsonNormal(rows);
        }


        [HttpGet("shebei_db_for_dj")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> shebei_db_for_dj()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var rows = await Service.get_dj_from_bfmes();
            //var r = 0;

            //var r = 0;
            return JsonNormal(rows);
        }


        [HttpGet("dianjian_devices")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<string> dianjian_devices(string mes_data)
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用1111");
            JArray mes_data_final = JArray.Parse(mes_data);
            Console.WriteLine(mes_data_final[0]);
            //Console.WriteLine(shebei_type);
            //Console.WriteLine(mesid_);
            var info_ = mes_data_final[0];
            string shebei_type = (string)info_["shebei_type"];
            int mesid = (int)info_["mesid"];
            string r = await Service.dianjian_daojiao_devices(shebei_type,mesid);
            //string r = "k";
            //var r = 0;

            //var r = 0;
            return r;
        }
        [HttpGet("weibao_devices")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<JsonResult> weibao_devices()
        //public async Task<JsonResult> SyncProductionTask_wgjy([FromBody] PageDataOptions order_no_)

        {
            Console.WriteLine("get方法调用");
            var rows = await Service.get_wb_from_bfmes();
            //var r = 0;

            //var r = 0;
            return JsonNormal(rows);
        }


        [HttpGet("wb_devices")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<string> wb_devices(string mes_data)
        {
            Console.WriteLine("get方法调用1111");
            JArray mes_data_final = JArray.Parse(mes_data);
            Console.WriteLine(mes_data_final[0]);
            var info_ = mes_data_final[0];
            string shebei_type = (string)info_["shebei_type"];
            int mesid = (int)info_["mesid"];
            string wb_name = (string)info_["wb_name"];
            string r = await Service.wb_daojiao_devices(shebei_type, mesid, wb_name);
            return r;
        }

        [HttpGet("wb_done_final")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<string> wb_done_final(string mes_data)
        {
            Console.WriteLine("get方法调用1111");
            JArray mes_data_final = JArray.Parse(mes_data);
            Console.WriteLine(mes_data_final[0]);
            var info_ = mes_data_final[0];
            //string shebei_type = (string)info_["shebei_type"];
            //int mesid = (int)info_["mesid"];
            //string wb_name = (string)info_["wb_name"];
            ////  string option_type, JArray done_type, int mesid, string wb_name
            string r = await Service.wb_daojiao_done_devices((string)info_["option_type"], mes_data_final, (int)info_["id"], "aa");
            return r;

            //return "成功";
        }

        [HttpGet("get_order_quality")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_order_quality()
        {
            Console.WriteLine("get方法调用1111");
            //string order_name = mes_data;
            //Console.WriteLine(mes_data);
            object r = await Service.order_qulity_mes();

            return r;

            //return "成功";
        }

        [HttpGet("get_tech_db")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_tech_db(string mes_data)
        {
            Console.WriteLine("get方法调用1111");
            //string order_name = mes_data;
            //Console.WriteLine(type_option);
            Console.WriteLine(mes_data);
            JArray mes_data_ = JArray.Parse(mes_data);


            object r = await Service.technology_db(mes_data_);
            Console.WriteLine(r);
            return r;

            //return "成功";
        }
        [HttpPost("get_tech_db_lot_chaif")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_tech_db_lot_chaif()
        {
            Console.WriteLine("get方法调用222");

            var rows = await Service.technology_db_lot_chaifen();
            return rows;

            //return "成功";
        }


        [HttpGet("get_dj_gd_for_qulity")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_dj_gd_for_qulity()
        {
            Console.WriteLine("get方法调用1111");
            //string order_name = mes_data;
            //Console.WriteLine(type_option);
            //Console.WriteLine(mes_data);
            //JArray mes_data_ = JArray.Parse(mes_data);


            object r = await Service.get_db_djgdall();
            Console.WriteLine(r);
            return r;

            //return "成功";
        }


        [HttpGet("get_dj_gd_qulity_detail")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_dj_gd_qulity_detail()
        {
            Console.WriteLine("get方法调用1111");
            //string order_name = mes_data;
            //Console.WriteLine(type_option);
            //Console.WriteLine(mes_data);
            //JArray mes_data_ = JArray.Parse(mes_data);


            object r = await Service.get_db_quality_detailall();
            Console.WriteLine(r);
            return r;

            //return "成功";
        }


        [HttpGet("insert_quality_info_db")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> insert_quality_info_db(string mes_data)
        {
            Console.WriteLine("get方法调用1111");
            //string order_name = mes_data;
            //Console.WriteLine(type_option);
            Console.WriteLine(mes_data);
            Console.WriteLine(mes_data.Length);
            Console.WriteLine(mes_data.GetType);
            JObject mes_data_ = JObject.Parse(mes_data);
            Console.WriteLine(mes_data_["daojiao_quality_info_table1"]);

            object r = await Service.insert_qul_info(mes_data_);
            //Console.WriteLine(r);
            //object r = "";
            return r;

            //return "成功";
        }

        [HttpGet("get_real_data_db")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_real_data_db()
        {
            Console.WriteLine("查询数据库实时");


            object r = await Service.get_real_db();

            return r;


        }
        [HttpGet("insert_dvices_current_order")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> insert_dvices_current_order(string mes_data)
        {
            Console.WriteLine("get方法调用1111");
            //string order_name = mes_data;
            //Console.WriteLine(type_option);
            //Console.WriteLine(mes_data);
            //Console.WriteLine(mes_data.Length);
            //Console.WriteLine(mes_data.GetType);
            JObject mes_data_ = JObject.Parse(mes_data);
            //Console.WriteLine(mes_data_["daojiao_quality_info_table1"]);

            object r = await Service.insert_db_device_order(mes_data_);
            //Console.WriteLine(r);
            //object r = "";
            return r;

            //return "成功";
        }

        [HttpGet("get_per_little_lot_state")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_per_little_lot_state(string order_name)
        {
            Console.WriteLine("get方法调用1111");
            //string order_name = mes_data;
            //Console.WriteLine(type_option);
            //Console.WriteLine(mes_data);
            //Console.WriteLine(mes_data.Length);
            //Console.WriteLine(mes_data.GetType);
            //JObject mes_data_ = JObject.Parse(mes_data);
            //Console.WriteLine(mes_data_["daojiao_quality_info_table1"]);

            object r = await Service.get_per_little_lot_state_(order_name);
            //Console.WriteLine(r);
            //object r = "";
            return r;

            //return "成功";
        }

        [HttpGet("get_order_db")]
        [AllowAnonymous]
        //[HttpBody]
        public async Task<object> get_order_db()
        {
            Console.WriteLine("get方法调用_工单列表111111");

            var Data = Db.Queryable<daojiaoGD>()
                .ToList();
            object r = "";
            return Data;

            //return "成功";
        }

    }
}
